package com.mofish.zbserver.user.register.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mofish.zbserver.common.model.user.User;
import com.mofish.zbserver.user.register.RegisterService;
import com.mofish.zbserver.user.register.dao.RegisterDao;

@Service
@Transactional
public class RegisterServiceImpl implements RegisterService {

	@Resource
	private RegisterDao registerDao;

	/**
	 * 查询当前昵称是否有人占用
	 * @return user表中起该用户名的用户数量
	 */
	@Override
	public Integer getUserCountByU_name(String u_name) {
		return registerDao.selectUserCountByU_name(u_name);
	}

	/**
	 * 查询当前邮箱是否有用户占用
	 * @return user表中使用该email的用户数量
	 */
	@Override
	public Integer getUserCountByU_email(String u_email) {
		return registerDao.selectUserCountByU_email(u_email);
	}

	/**
	 * 获取新的u_id
	 * @return 完整的用户id
	 */
	@Override
	public String getUserNewU_id() {
		return registerDao.selectNewU_id();
	}

	/**
	 * 添加新用户，默认为普通用户
	 */
	@Override
	public void addUser(User user) {
		// 向user表中添加新用户
		registerDao.insertUser(user);
	}

}
